package com.hsgene.util.redis.config;

import com.hsgene.common.util.exception.GlobalExceptionHandler;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

/**
 * MVC配置
 *
 * @author wangbing
 * @version 1.0, 2018/7/5
 */
@Configuration
public class UserWebMvcConfigurer implements WebMvcConfigurer {

    @Value("${global.exception.enable}")
    private String globalExceptionEnable;

    /**
     * 全局异常捕获配置
     *
     * @param resolvers
     */
    @Override
    public void configureHandlerExceptionResolvers(List<HandlerExceptionResolver> resolvers) {
        resolvers.add(new GlobalExceptionHandler(isGlobalExceptionEnable()));
    }

    private boolean isGlobalExceptionEnable() {
        return Boolean.TRUE.toString().equalsIgnoreCase(globalExceptionEnable);
    }
}
